/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rgenerator;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.crypto.SealedObject;

/**
 *
 * @author alex2stf <alex2stf@yahoo.com>
 */
public class Serialization {
    String appPath;
            
    public Serialization(){
    appPath=Serialization.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    
     System.out.println(" saving current settings into "+Serialization.class.getProtectionDomain().getCodeSource().getLocation().getPath()+"");
    
    }
    
    
    public void writeFile(SerialObject param){
        
        try{
        FileOutputStream fstream=new FileOutputStream("settings.dat");
        ObjectOutputStream ostream=new ObjectOutputStream(fstream);
        ostream.writeObject(param);
        }
        catch (Exception ex) {
            System.out.println("exception occured");
        }
    }
    
    
    public SerialObject readFile(){
        //aici vine default:
        SerialObject obj=new SerialObject("com.res", "R", "C:/", "C:/", true, false, false, false, "C:/", "C:/");
        
        try{
         FileInputStream ifstream=new FileInputStream("settings.dat");
         ObjectInputStream iostream=new ObjectInputStream(ifstream);
         obj=(SerialObject)iostream.readObject();
         
         System.out.println(obj.getInputFolderPath());
        }
        catch (Exception ex) {
            System.out.println(" may be the first run");
        }
        
        return obj;
    }
    
}
